Nextflow ‘rnaseq_count_nf’ Pipeline Run Instructions

1 About the Workflow

This workflow is designed to output gene expression counts from STAR aligner using --quantmode. It will also perform general QC statistics on the fastqs with fastqc and the alignment using rseqc. Finally, the QC reports are collected into a single file using multiQC.

A DAG (directed acyclic graph) of the workflow is show below:

2 Set-up Nextflow Environment

First, fork the repository from Children’s bitbucket. Do this by clicking the “create fork” symbol from the bitbucket web interface and fork it to your personal bitbucket account, as illustrated below.

Next, you will need to clone your personal repository to your home in Cybertron. See the image below for where you can find the correct URL on your forked bitbucket repo.

Copy that URL to replace https://childrens-atlassian/bitbucket/scm/~jsmi26/rnaseq_count_nf.git below.

#on a terminal on the Cybertron login nodes
cd ~

# your fork should have your own userID (rather than jsmi26)
git clone https://childrens-atlassian/bitbucket/scm/~jsmi26/rnaseq_count_nf.git

Finally, grab a compute node and activate the conda environment. It is also be best practice to use tmux or screen to ensure that if at the session is disconnected, then you’re nextflow workflow (if running) won’t end with SIGKILL error.

#Find your project code by listing all your projects on the Cybertron terminal
project info

#Grab a compute note
qsub -I -q freeq -l select=1:ncpus=1:mem=8g -l walltime=8:00:00 -P [PROJECT CODE]
cd /path/to/cloned/rnaseq_count_nf

If you don’t have conda installed yet, please follow these directions. You may stop following the directions after the conda deactivate step.

#Create the environement only once. Skip this step if you've already created the environment
conda env create -f env/nextflow.yaml

#Activate the conda environment. 
conda activate nextflow

3 Test the Workflow

3.1 Edit the Config File

Edit the nextflow.config file in any text editor; the example below is in R. You will need to change the project code (use the same one as you used above), and the queue name to be paidq or a tier 3 queue. Paidq will cost less than $0.01 for testing with the workflow’s example data provided in the directory test_data.

usethis::edit_file("../nextflow.config")
//global parameters
params {
    // general options
    sample_sheet                = "test_data/paired_end_sample_sheet.csv"
    download_sra_fqs            = false
    queue                       = 'paidq'
    project                     = '[PROJECT CODE]'
<...continues...>

3.2 Paired-end example

Determine if the workflow works on your installation of the conda environment by running the following command.

./main_run.sh "paired_end_test"

3.3 Single-end example

To test the single-end sheet, modify the sample_sheet parameter in the nextflow.config and the output directory (outdir).

params {
    // general options
    sample_sheet                = "test_data/single_end_sheet.csv"
    [...]
    outdir                      = "./single_end_results/"
<...continues...>
}

then run the command

./main_run.sh "single_end_test"

3.4 sra download example

To test the sra sample sheet - modify these the sample sheet, and set download_sra_fastqs to true in the nextflow.config and the output directory (outdir).

params {
    // general options
    sample_sheet                = "test_data/sra_sample_sheet.csv"
    download_sra_fqs            = true
    [...]
    outdir                      = "./sra_results/"
<...continues...>
}

then run on the command:

./main_run.sh "sra_test"

4 Modify the Pipeline for Your Data

4.1 Define Input Files

A comma delimited (csv) sample sheet is required for the input samples to be processed. Please note, do not remove the comment lines that begin with “#” in the example files. The same number of comment lines must be included in any input sample sheet, based on the examples provided here.

It must have the column names (in any order):

  • r1 - the filepath for the read 1 fastq in paired-end RNA-seq, or the single-end fastq file

  • r2 - the filepath for the read 2 fastq in paired-end RNA-seq

  • id - unique sample ID, no duplicates allowed in the sample sheet

  • single_end - boolean [true/false] if the data is single-end or paired-end

TO DO: A function provided here, but it may not meet the needs of every experiment.

The two examples are provided here to look at:

example_sheet <- read.csv(here::here("test_data/paired_end_sample_sheet.csv"),
    header = TRUE, comment.char = "#")
example_sheet

If downloading the fastq files directly from the SRA, the sample sheet only requires the id and the single_end columns.

sra_example <- read.csv(here::here("test_data/sra_sample_sheet.csv"),
    header = TRUE, comment.char = "#")

sra_example

4.2 Nextflow Config

Edit the nextflow.config file to include the appropriate filepaths for the samples to be included in the pipeline, and the appropriate genome references. The required files are listed here:

workDir = "PATH/TO/SCRATCH" 

//global parameters
params {
    // general options
    sample_sheet                = "PATH/TO/SAMPLE_SHEET"
    download_sra_fqs            = [true/false]
    queue                       = 'NAME OF QUEUE'
    project                     = 'PROJECT CODE'
    outdir                      = "PATH/TO/RESULTS"

    //star specific params. Must be full filepaths for files outside the projectDir
    index                       = 'PATH/TO/STAR_INDEX/' [optional if build_index == true]
    build_index                 = false
    gtf                         = 'PATH/TO/GTF'
    fasta                       = 'PATH/TO/FASTA' [optional if build_index == false ]
    star_ignore_sjdbgtf         = false

    //trimgalore module specific parameters
    trim                        = [true/false]

    //RSEQC specific parameters
    gene_list                   = 'PATH/TO/RSEQC/rRNA.bed'
    ref_gene_model              = 'PATH/TO/RSEQC/gene_model.bed'
}

The gene_list and ref_gene_model can be found at the RSEQC documentation page and are located at /gpfs/shared_data to share with the SCRI.

However, the ref_gene_model must be in BED12 format and must match the transcript IDs used in the GTF for STAR aligner. The BED12 can be produced from the GFT file using UCSC utilities (Kent tools).

4.3 Advanced Options

TO DO: add “Advanced Options” section to describe the ext.args under the process scope.

5 Run the workflow

Then execute a wrapper around the nextflow run main.nf command which is in the main_run.sh shell script. Provide a descriptive name (string) for your workflow run, in this example we will use “my_analysis”.

Typically, you will not need to change the main_run.sh often.

The main_run.sh script defines the profiles for different executors in the variable NFX_PROFILE. The choices for profiles are:

  • PBS_singularity [default]
  • local_singularity
  • PBS_conda

“PBS_singularity” is recommended. This profiles executes the jobs on the HPC using the PBS scheduler and then will run the job inside singularity containers with the appropriate scientific software versions.

“local_singularity” is good for workflow development if you’re making a lot of changes. This will use singularity on Cybertron, but run the jobs on the interactive compute node that you’ve requested during “Set-up Nextflow Environment” steps above.

“PBS_conda” is generally not recommended.This profiles executes the jobs on the HPC using the PBS scheduler. Then nextflow will coordinate the creation of conda environments for each step in the workflow and active those environments in the scheduled compute nodes for job.

./main_run.sh "my_analysis"

You can also change the entry_point for the workflow to run only the index building step using NFX_ENTRY='star_index'. You can run only the download step for SRA files by setting NFX_ENTRY='sra_fastqs'. Keep the default NFX_ENTRY='rnaseq_count' to run the complete pipeline.

6 Expected Outputs

Under the path provided in the nextflow config for params “outdir”, you will find directories named for each of the modules. Lets say “params.outdir = ./results”. There will be the following file structure:

results/

  • fastqc/
    • fastqc_{sample_id}_/
  • multiqc/
    • {sample_sheet_basename}multiqcreport_data/
    • collects fastqc, star alignment, and star quantification stats
  • rseqc/
    • {sample_id}.rRNA_stats.out
    • {sample_id}.in.bam - rRNA reads
    • {sample_id}.Aligned.sortedByCoord.out.summary.txt
    • {sample_id}.Aligned.sortedByCoord.out.tin.xls
    • {sample_id}.read_distribution.txt
  • samtools/
    • bam index (.bai) file
  • sratools/
    • {SRR_RUN_ID}.fastq.gz
    • sratoolkit config file
  • star/
    • {Sample_ID_001}.Aligned.out.bam
    • {Sample_ID_001}.Log.final.out
    • {Sample_ID_001}.Log.out
    • {Sample_ID_001}.Log.progress.out
    • {Sample_ID_001}.ReadsPerGene.out.tab
    • {Sample_ID_001}.SJ.out.tab

In addition, there will be an HTML report with information on where the temp data is stored in the workDir path, and general run statistics such as resource utilized versus requested, which helps with optimization. It will also provide information on how much walltime was used per sample, total CPU hours, etc.

The HTML file is found in reports directory and will have the prefix defined on the command line when the ./main_run.sh "my_analysis" was invoked, so in this example it would be named “my_analysis_{DATE}.html”.

There will also be a detailed nextflow log file that is useful for de-bugging which will also be named in this example, “my_analysis_{DATE}_nextflow.log”.

Finally, the pipeline will produce a DAG - Directed acyclic graph which describes the workflow channels (inputs) and the modules. The DAG image will be saved under dag/ directory with the name “my_analysis_{DATE}_dag.pdf”.

7 Share the Data

RESULTS="PATH/TO/PIPELINE/RESULTS/"
OUTDIR="path/to/collabs/RSS"
rsync -av $RESULTS $OUTDIR 

8 Cleaning up Cached Data

Nextflow has an utility to clean up old work directories and logs that are no longer needed. This can be run after any amount of time to keep your workdir from getting too large or if you’re running out of disk space.

This requires the session ID or session name, which can found in the .nextflow/history file.

nextflow log
nextflow clean -f [RUN NAME]

9 Session Information

sessionInfo()